﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PeoplesJukebox.Core.TrackLists.Bases;
using PeoplesJukebox.Core.Configuration;
using PeoplesJukebox.Core.MediaItems.Bases;
using items = PeoplesJukebox.Core.MediaItems;

namespace PeoplesJukebox.Core.TrackLists
{
    /// <summary>
    /// Tracklist based on a configured collection of tracks
    /// </summary>
    public class ConfiguredTrackList : TrackListBase
    {
        private int _index = 0;

        /// <summary>
        /// Default constructor
        /// </summary>
        public ConfiguredTrackList() { }
        
        /// <summary>
        /// Gets the name of the tracklist
        /// </summary>
        public override string Name
        {
            get { return "Configured"; }
        }

        /// <summary>
        /// Returns whether there are any configured tracks left
        /// </summary>
        public override bool HasTracks
        {
            get
            {
                return TrackConfiguration.Current != null &&
                       TrackConfiguration.Current.ConfiguredTracks.Count > this._index;
            }
        }

        /// <summary>
        /// Returns the ID of the next configured track to play
        /// </summary>
        /// <returns>Track ID</returns>
        protected override int GetNextTrackId()
        {
            int trackId = this.GetConfiguredTrackId(TrackConfiguration.Current.ConfiguredTracks, this._index);
            this._index++;
            return trackId;
        }

        /// <summary>
        /// Loads the configured tracks
        /// </summary>
        public override void Load()
        {
            base.Load();
            this._index = 0;
        }
    }
}